<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用户列表 - 用户管理 - 本站用户</title>
<?php include(P_TEMPLATE . '/admin/header.tpl.php'); ?>
<script>
$(function(){
	var html=['<form id="form1" name="form1" method="post">',
						'<div class="form-box">',
							'<div class="form-row">',
								'<label for="text" class="form-field">帐号名称</label>',
								'<div class="form-cont">',
									'<input type="text" value="" class="ipt-txt" id="username" name="username" vrel="_f|ne|sz=max:40,m:不能超过20个字,ww" warntip="#nameErr"><span id="nameErr" class="tips-error hidden"></span>',
								'</div>',
							'</div>',
							'<div class="form-row">',
								'<label for="text" class="form-field">密码</label>',
								'<div class="form-cont">',
									'<input type="password" value="" class="ipt-txt" id="pwd" name="pwd" vrel="_f|ne|sz=max:40,m:不能超过20个字,ww" warntip="#pwdErr"><span id="pwdErr" class="tips-error hidden"></span>',
								'</div>',
							'</div>',
							'<div class="form-row">',
								'<label for="text" class="form-field">确认密码</label>',
								'<div class="form-cont">',
									'<input type="password" value="" class="ipt-txt" id="re_pwd" name="re_pwd" vrel="_f|ne|sz=max:40,m:不能超过20个字,ww" warntip="#rePwdErr"><span id="rePwdErr" class="tips-error hidden"></span>',
								'</div>',
							'</div>',
							'<div class="btn-area">',
								'<a class="btn-general  highlight" id="input_ok" href="#"><span>确定</span></a>',
								'<a class="btn-general" id="input_cancle" href="#"><span>取消</span></a>',
							'</div>',
						'</div>',
					'</form>'].join('');

	window.box=Xwb.use('MgrDlg',{
		setTitle:function(title){
			this.dlg.jq('#xwb_title').html(title);
			return this;
		},

		set: function(user, pwd, re_pwd) {
			$('input[name=username]', this.dlg.jq()).val(user || '');
			$('input[name=pwd]', this.dlg.jq()).val(pwd || '');
			$('input[name=re_pwd]', this.dlg.jq()).val(re_pwd || '');
			return this;
		 },

	   show:function(){
		 this.dlg.jq('#textErr').cssDisplay(false);
		 this.dlg.display(true);
	   },

	   hide:function(){
		this.dlg.display(false);
	   },

	   onOk:function(fn){
			this.selfChk=function(data){
				fn(data.username, data.pwd, data.re_pwd);
			}
	   },

	   modeHtml:html,
	   dlgcfg:{
			cs:'win-link win-fixed',
			title:'添加管理员帐号',
			onViewReady:function(view){
				var self=this;
				$(view).find('#input_cancle').click(function(){
					self.close();
				})
			}
	   },

	   valcfg:{
		    form:'#form1',
			trigger:'#input_ok'
	   }
	});

	box.dlg.close();
});
</script>
<script>
$(function() {
	var errNodes = {
		'name': box.dlg.jq().find('#nameErr'),
		'pwd': box.dlg.jq().find('#pwdErr'),
		're_pwd': box.dlg.jq().find('#rePwdErr')
	};
	
	var target;
	var $username =box.dlg.jq().find('#username');
	var $pwd =box.dlg.jq().find('#pwd');
	var $re_pwd =box.dlg.jq().find('#re_pwd');

	box.onOk(function(username, pwd, re_pwd) {
		var data = {
			username: username,
			pwd: pwd,
			re_pwd: re_pwd
		}
		
		$.ajax({
			url: "/admin.php?m=admin/admin.addAdmin", 
			data: data,
			type: 'post',
			dataType: 'json',
			success: function(ret) {
				if (ret.rst) {
					location.reload();
				} else { //失败
					Xwb.ui.MsgBox.alert('添加失败', ret.err);
				}
				target = null;
			}
		});
	});

	$('.main-cont').click(function(e) {
		var $target = $(e.target);
		var rel = $target.attr('rel');

		if (!rel) {
			return;
		} else {
			var tmp = rel.split(':');
			var op = tmp[0];
			var v = tmp[1] || '';
		}

		target = e.target;

		switch (op) {
			case 'add':
				$.each(errNodes, function(i, o) {
					o.addClass('hidden');
				});
				box.setTitle('添加管理员帐号').set('', '', '').show();
				break;

			case 'del':
				var $tr = $target.closest('TR');
				Xwb.ui.MsgBox.confirm('删除提示','确定要删除这个管理员帐号？',function(id){
					if(id=="ok"){
						$.ajax({
							url: "/admin.php?m=admin/admin.delAdmin",
							data: {
								admin_id: v,
								op: 'del'
							},
							type: 'post',
							dataType: 'json',
							success: function(ret) {
								if (ret.rst) {
									location.reload();
								} else {
									Xwb.ui.MsgBox.alert('删除失败', ret.err);
								}
							}
						});
					}
				});
				target = null;
				break;
		}
	});
});
</script>
</head>
<body class="main-body">
	<div class="path"><p>当前位置：系统管理<span>&gt;</span>后台帐号管理<span>&gt;</span>帐号列表</p></div>
    <div class="main-cont">
    	<h3 class="title"><a href="<?php echo URL('admin/admin.addAdmin'); ?>" class="btn-general"><span>添加帐号</span></a>帐号列表</h3>
		<div class="set-area">
			<table class="table" cellpadding="0" cellspacing="0">
            	<colgroup>
                	<col class="w70" />
                	<col />
                	<col class="w90" />
                	<col class="w150" />
                	<col class="w100" />
                	<col class="w140" />
                </colgroup>
                <thead class="tb-tit-bg">
                	<tr>
                    	<th><div class="th-gap">用户ID</div></th>
                    	<th><div class="th-gap">帐号名称</div></th>
                    	<th><div class="th-gap">分组</div></th>
                    	<th><div class="th-gap">添加时间</div></th>
                    	<th><div class="th-gap">操作者</div></th>
                    	<th><div class="th-gap">操作</div></th>
                    </tr>
                </thead>
                <tfoot class="td-foot-bg">
					<tr>
						<td colspan="6">
						</td>
					</tr>
                </tfoot>
                <tbody>
                	<?php if (is_array($userList) && !empty($userList)): ?>
                	<?php foreach ($userList as $user): ?>
                	<tr>
                    	<td><?php echo $user['admin_id']; ?></td>
                    	<td><?php echo F::escape($user['username']); ?></td>
                    	<td><?php F::O( isset($groupList[$user['group_id']])?$groupList[$user['group_id']]['group_name']:'' ); ?></td>
                    	<td><?php echo date('Y-m-d H:i:s', $user['add_time']); ?></td>
                    	<td><?php echo F::escape($user['opt_user']); ?></td>
                    	<td><a href="javascript:;" class="icon-del" rel="del:<?php echo $user['admin_id']; ?>">删除</a><a href="<?php echo URL('admin/admin.setPermissions', array('aid' => $user['admin_id'])); ?>" class="icon-set">设置权限</a></td>
                    </tr>
                    <?php endforeach; ?>
                    <?php else: ?>
                    <tr>
                    	<td colspan="6">查无记录</td>
                    </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
</body>
</html>